package com.example.home.livingPayment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;

import androidx.appcompat.app.AppCompatActivity;

import com.example.home.R;
import com.example.home.livingPayment.activity.PaymentActivity;

import java.util.ArrayList;
import java.util.List;

public class LivingPaymentMainActivity extends AppCompatActivity {
    private ImageView back;
    private ImageView history;
    private Spinner spinnerOptions;
    private EditText inputField;
    private Button btnCheck;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_living_payment_main);
        initView();
        List<String> options = new ArrayList<>();
        options.add("中国移动");
        options.add("中国联通");
        options.add("中国电信");

        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, options);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerOptions.setAdapter(adapter);

        // 设置一个监听器来处理项目选择
        spinnerOptions.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
                // 处理选中的元素
                String selectedOption = options.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parentView) {

            }
        });
    }

    private void initView() {


        back = findViewById(R.id.back);
        history = findViewById(R.id.history);
        spinnerOptions = findViewById(R.id.spinnerOptions);
        inputField = findViewById(R.id.inputField);
        btnCheck = findViewById(R.id.btn_check);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LivingPaymentMainActivity.this.finish();
            }
        });
        btnCheck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String phonenumber = inputField.getText().toString();
                Intent intent = new Intent(LivingPaymentMainActivity.this, PaymentActivity.class);
                intent.putExtra("phonenumber",phonenumber);
                startActivity(intent);
            }
        });
    }
}